import redis

# 连接Redis
conn = redis.Redis(host="192.168.5.132")

# 添加元素
# mapping = {"张三": 20, "李四": 30, "王五": 10, "赵六": 90}
# conn.zadd("games_rank", mapping=mapping)


# 获取所有的元素
# games_rank = conn.zrange("games_rank", 0, -1)  # 默认是升序
# for item in games_rank:
#     print(item.decode("utf-8"))

# 降序
# games_rank = conn.zrevrange("games_rank", 0, -1)
# for item in games_rank:
#     print(item.decode("utf-8"))


# 显示分数
# games_rank = conn.zrange("games_rank", 0, -1, withscores=True)
#
# for name, score in games_rank:
#     print(name.decode("utf-8"), " :", score)


# 修改分数
# conn.zincrby("games_rank", 50, "张三")
# games_rank = conn.zrange("games_rank", 0, -1, withscores=True)
#
# for name, score in games_rank:
#     print(name.decode("utf-8"), " :", score)